<?php
/**
*   Will set the global variables
*   @author Renan Henrique Abreu <renanhabreu@gmail.com>
*   @date 16-06-2009
*   @version 2.0
*   @abstract
*   @package Nucleo
*   @subpackage Nucleo.Registry
*   @copyright 2009 Renan Abreu
*/
abstract class Nucleo_Registry_Registry{
	static private $globals = null;
	static private $globalFile = false;
	
	/**
	 * Set a  global variable
	 * @param string Global name
	 * @param $value Value of global
	 */
	static public function set($name,$value){
		self::$globals[$name] = $value;
	}
	
	/**
	 * Get a global variable
	 * @param string Global name
	 * @return null || global
	 */
	static public function get($name){
		$retorno = null;
		if(isset(self::$globals[$name])){
			$retorno = self::$globals[$name];
		}
		return $retorno;
	}
	
	/**
	 * Check if exists the variable
	 * @param string Variable name
	 * @return true || false
	 */
	static public function isAdded($name){
		return isset(self::$globals[$name]);
	}
	
	/**
	 * Will read a configuration file ( type ini )
	 * VAR_NAME = value
	 * @return null
	 */
	static public function load($configFile){

		if(!self::$globalFile){
			$configArray = parse_ini_file($configFile,true);
                        if($configArray){
				foreach ($configArray as $key=>$value){
					$key = strtoupper($key);
					Nucleo_Registry_Registry::set($key,$value);
				}
				self::$globalFile = true;
			}else{
			throw new Nucleo_Exception_Sifra('011');
			}
		}
			
	}
}
?>